﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VkcomAPI;
using VkcomAPI.PublicTypes;

namespace VkcomAPI
{

    /// <summary>
    /// Представляет собой постройщик URL в зависимости от переданной информации о пользователе.
    /// </summary>
    public class UrlBuilder
    {
        private readonly UserCredentials credentials;
        private readonly TokenAndID tokenAndId;

        public UrlBuilder(UserCredentials userCredentials, TokenAndID tokenAndId)
        {
            this.credentials = userCredentials;
            this.tokenAndId = tokenAndId;
        }

        public string LoginUrl
        {
            get
            {
                return string.Format(@"http://vk.com/login.php?m=1&email={0}&pass={1}", credentials.Login, credentials.Password);
            }
        }

        public string WhitespaceSymbol
        {
            get
            {
                return @"%20";
            }
        }

        public string LoginRequest()
        {
            return string.Format(@"login.vk.com/?act=login&q=1&al_frame=1&expire=&captcha_sid=&captcha_key=&from_host=vkontakte.ru&email={0}%40mydomain.com&pass={1}",
                credentials.Login, credentials.Password);
        }

        public string LoginRequest(UserCredentials credentials)
        {
            throw new NotImplementedException();
        }

        public string CreateSearchUri(string searchText)
        {
            searchText.Replace(" ", WhitespaceSymbol);
            return string.Format(@"https://api.vk.com/method/audio.search.xml?q={0}&access_token={1}", searchText, tokenAndId.AccessToken);
        }

        public string CreateGetAllMusicUri()
        {
            return string.Format(@"https://api.vk.com/method/audio.get?access_token={0}", tokenAndId.AccessToken);
        }

    }
}
